package com.soft.app.ruanba.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.soft.app.ruanba.down.Soft;

public class SoftDAO extends BaseHibernateDAO
{

	private static final Logger log = LoggerFactory.getLogger(SoftDAO.class);

	public SoftDAO()
	{
	}

	public void save(Soft transientInstance)
	{
		log.debug("saving Soft instance:{}", transientInstance);
		try
		{
			getSession().save(transientInstance);
			log.debug("save successful");
		}
		catch (RuntimeException re)
		{
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Soft persistentInstance)
	{
		log.debug("deleting Soft instance");
		try
		{
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		}
		catch (RuntimeException re)
		{
			log.error("delete failed", re);
			throw re;
		}
	}

	public Soft findById(String id)
	{
		log.debug((new StringBuilder()).append("getting Soft instance with id: ").append(id).toString());
		Soft instance = (Soft)getSession().get("com.soft.app.ruanba.down.Soft", id);
		return instance;
	}

	public java.util.List findByExample(Soft instance)
	{
		log.debug("finding Soft instance by example");
		java.util.List results;
		results = getSession().createCriteria("com.soft.app.ruanba.down.Soft").add(org.hibernate.criterion.Example.create(instance)).list();
		log.debug((new StringBuilder()).append("find by example successful, result size: ").append(results.size()).toString());
		return results;
	}

	public java.util.List findByProperty(String propertyName, Object value)
	{
		log.debug("finding Soft instance with property: {}, value: {}", propertyName, value);
		org.hibernate.Query queryObject;
		String queryString = (new StringBuilder()).append("from Soft as model where model.").append(propertyName).append("= ?").toString();
		queryObject = getSession().createQuery(queryString);
		queryObject.setParameter(0, value);
		return queryObject.list();
	}

	public Soft findByUniqueKey(String keyName, Object value)
	{
		log.debug("查找movie[{}={}],", keyName, value);
		String queryString = (new StringBuilder()).append("from Soft soft where soft.").append(keyName).append("= ?").toString();
		org.hibernate.Query query = getSession().createQuery(queryString);
		query.setParameter(0, value);
		return (Soft)query.uniqueResult();
	}

	public Soft findBySource(String source)
	{
		return findByUniqueKey("source", source);
	}

	public java.util.List findAll()
	{
		log.debug("finding all Soft instances");
		org.hibernate.Query queryObject;
		String queryString = "from Soft";
		queryObject = getSession().createQuery(queryString);
		return queryObject.list();
	}

	public Soft merge(Soft detachedInstance)
	{
		log.debug("merging Soft instance");
		Soft result;
		result = (Soft)getSession().merge(detachedInstance);
		log.debug("merge successful");
		return result;
	}

	public void attachDirty(Soft instance)
	{
		log.debug("attaching dirty Soft instance");
		try
		{
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		}
		catch (RuntimeException re)
		{
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Soft instance)
	{
		log.debug("attaching clean Soft instance");
		try
		{
			getSession().lock(instance, org.hibernate.LockMode.NONE);
			log.debug("attach successful");
		}
		catch (RuntimeException re)
		{
			log.error("attach failed", re);
			throw re;
		}
	}

	public long countAll(String status)
	{
		String sql = " select count(pi) from Soft pi where status = :status ";
		org.hibernate.Query q = getSession().createQuery(sql);
		q.setString("status", status);
		return Long.parseLong(q.uniqueResult().toString());
	}

	public java.util.List getSoftList(int start, int size, String status)
	{
		String sql = "from Soft pi where status = :status ";
		org.hibernate.Query q = getSession().createQuery(sql);
		q.setString("status", status);
		q.setFirstResult(start);
		q.setMaxResults(size);
		return q.list();
	}

}